home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / curses / t.c < prev    next >
C/C++ Source or Header  |  1994-04-08  |  6KB  |  265 lines

  1. #include "curses.h"
  2.  
  3. char    rule[] = "----.----";
  4.  
  5. #ifdef __AUX__
  6. #define wechochar(w, c) (waddch((w),(c)),wrefresh((w)))
  7. #endif
  8.  
  9. #define    ABORT(s)    { fputs(s,stderr); abort(); }
  10.  
  11. static char *pad_init1 = "xxxxxxxxxxYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY********************";
  12. static char *pad_init2 = "xxxxxxxxxxZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ********************";
  13. static char *pad_init3 = "****************************************************************************************************";
  14.  
  15. main()
  16. {
  17.     int i, j;
  18.     WINDOW *win1 = NULL;
  19.     WINDOW *win2 = NULL;
  20.     WINDOW *pad = NULL;
  21.  
  22.     /*
  23.      * Test isendwin(), initscr(), and refresh():
  24.      */
  25.  
  26. /* #ifndef __AUX__ (* isendwin doesn't seem to be false b4 initialization on sun *)
  27.  *    if (!isendwin())
  28.  *    ABORT("isendwin() is false (s/b true)\n");
  29.  *#endif
  30. */
  31.     initscr();
  32.     refresh();
  33.     noecho();
  34.     crmode();
  35.  
  36. #ifndef __AUX__
  37.     if (isendwin()) 
  38.     ABORT("isendwin() is true (s/b false)\n");
  39. #endif
  40.  
  41.     /*
  42.      * Test printw():
  43.      */
  44.  
  45.     for (i = 0, j = 2 * COLS / 10; i < j; i++)
  46.         printw("%s%d", rule, i%10);
  47.  
  48.     refresh();
  49.     getch();        /* getch() does an implicit refresh() */
  50.  
  51.     /*
  52.      * Create a window and test wrefresh()
  53.      */
  54.  
  55.     win1 = newwin(10,10,10,10);
  56.  
  57.     mvaddstr(4,0,"This should not be printed");
  58.     wprintw(win1, "1234567890nextline");
  59.     wrefresh(win1);    /* only refresh win1 */
  60.     wgetch(win1);
  61.  
  62.     mvaddstr(4,0,"The 123456... message should disappear");
  63.     clearok(stdscr, TRUE);
  64.     refresh();            /* overlay stdscr over window */
  65.     getch();
  66.  
  67.     pad = newpad(LINES + LINES/3, 100);
  68.     for (i = 0; i < LINES/3; i++)
  69.         mvwaddstr(pad, i, 0, pad_init1);
  70.  
  71.     for (i = LINES/3; i < LINES; i++)
  72.         mvwaddstr(pad, i, 0, pad_init2);
  73.  
  74.     for (i = LINES; i < LINES + LINES/3; i++)
  75.         mvwaddstr(pad, i, 0, pad_init3);
  76.  
  77.     wmove(pad, 0, 0);
  78.     prefresh(pad, 0, 0, 0, 0, LINES, COLS);
  79.     wgetch(pad);
  80.  
  81.     prefresh(pad, LINES/8, 10, 0, 0, LINES, COLS);
  82.     wgetch(pad);
  83.  
  84.     /*
  85.      * Test line drawing characters:
  86.      */
  87.  
  88. #if !defined(THINK_C) && !defined(__AUX__)
  89.     wclear(win1);
  90.     wmove(win1,0,0);
  91.     mvwaddch(win1,0,0,ACS_ULCORNER);
  92.     waddch(win1,ACS_HLINE);
  93.     waddch(win1,ACS_TTEE);
  94.     waddch(win1,ACS_HLINE);
  95.     waddch(win1,ACS_URCORNER);
  96.     mvwaddch(win1,1,0,ACS_VLINE);
  97.     waddch(win1,' ');
  98.     waddch(win1,ACS_VLINE);
  99.     waddch(win1,' ');
  100.     waddch(win1,ACS_VLINE);
  101.     mvwaddch(win1,2,0,ACS_LTEE);
  102.     waddch(win1,ACS_HLINE);
  103.     waddch(win1,ACS_PLUS);
  104.     waddch(win1,ACS_HLINE);
  105.     waddch(win1,ACS_RTEE);
  106.     mvwaddch(win1,3,0,ACS_VLINE);
  107.     waddch(win1,' ');
  108.     waddch(win1,ACS_VLINE);
  109.     waddch(win1,' ');
  110.     waddch(win1,ACS_VLINE);
  111.     mvwaddch(win1,4,0,ACS_LLCORNER);
  112.     waddch(win1,ACS_HLINE);
  113.     waddch(win1,ACS_BTEE);
  114.     waddch(win1,ACS_HLINE);
  115.     waddch(win1,ACS_LRCORNER);
  116.     wrefresh(win1);
  117.     wgetch(win1);
  118. #endif
  119.  
  120.     /*
  121.      * Make 2 boxed windows and display both at the same time:
  122.      */
  123.  
  124.     wclear(win1);
  125.     box(win1,0,0);
  126.     wnoutrefresh(win1);        /* Update internal but not screen */
  127.     sleep(1);            /* Make the delay noticeable */
  128.  
  129.     win2 = newwin(10,10,10,40);
  130.     box(win2,'|','-');        /* Cheap box */
  131.     wnoutrefresh(win2);        /* Update second window */
  132.     sleep(1);
  133.  
  134.     doupdate();            /* Now update both at once */
  135.     getch();
  136.  
  137.     mvwin(win2,10,30);        /* Move window 2    */
  138.     touchwin(win1);        /* Reshow window 1    */
  139.     touchwin(stdscr);        /* Reshow window 1    */
  140.     wnoutrefresh(stdscr);    /* Update stdscr    */
  141.     wnoutrefresh(win1);        /* Update window 1    */
  142.     wnoutrefresh(win2);        /* Update window 2    */
  143.     doupdate();            /* And display new screen    */
  144.     getch();
  145.  
  146.     wmove(win2,3,3);
  147.     wechochar(win2,'*');
  148.     getch();
  149.  
  150. #ifdef __AUX__
  151.     overwrite(pad, win1);
  152. #else
  153.     copywin(pad, win1, LINES/6, 5, 1, 1, 9, 9, FALSE);
  154. #endif /* __AUX__ */
  155.     wrefresh(win1);
  156.     getch();
  157.  
  158.     endwin();
  159. #ifndef __AUX__
  160.     if (!isendwin())
  161.     ABORT("isendwin() is true (s/b false)\n");
  162. #endif
  163.  
  164.     clear();
  165.     delwin(win2);
  166.     win2 = newwin(8,8,11,11);        /* win2 is now inside win1 */
  167.     touchwin(win1);
  168.     move(0,0);
  169.     standout();
  170.     addstr("STANDOUT ");
  171.     standend();
  172.     addstr("STANDEND ");
  173.     attrset(A_UNDERLINE);
  174.     addstr("UNDERLINE ");
  175.     attrset(A_REVERSE);
  176.     addstr("REVERSE ");
  177.     attrset(A_BLINK);
  178.     addstr("BLINK ");
  179.     attrset(A_BOLD);
  180.     addstr("BOLD ");
  181.     attrset(A_DIM);
  182.     addstr("DIM ");
  183.     attrset(A_NORMAL);
  184.     addch('\n');
  185.  
  186.     attron(A_REVERSE);
  187.     addstr("REVERSE ");
  188.     attron(A_BOLD);
  189.     addstr("BOLD ");
  190.     attron(A_DIM);
  191.     addstr("DIM ");
  192.     attron(A_UNDERLINE);
  193.     addstr("UNDERLINE ");
  194.     attron(A_BLINK);
  195.     addstr("BLINK ");
  196.     attron(A_NORMAL);
  197.     addch('\n');
  198.  
  199.     attroff(A_REVERSE);
  200.     addstr("REVERSE ");
  201.     attroff(A_BOLD);
  202.     addstr("BOLD ");
  203.     attroff(A_DIM);
  204.     addstr("DIM ");
  205.     attroff(A_UNDERLINE);
  206.     addstr("UNDERLINE ");
  207.     attroff(A_BLINK);
  208.     addstr("BLINK ");
  209.     attroff(A_NORMAL);
  210.     addch('\n');
  211.     beep();
  212.     refresh();
  213.     getch();
  214.  
  215.     clear();
  216.     for (i = 0; i < LINES; i++) {
  217.         move(i,0);
  218.         printw("The quick brown fox jumps over the lazy dog %d times", i);
  219.     }
  220.     attrset(A_BOLD);
  221.     mvaddstr(4,5,"clrtoeol():");
  222.     clrtoeol();
  223.     mvaddstr(6,5,"delch():");
  224.     delch();
  225.     mvaddstr(8,5,"deleteln() below:");
  226.     move(9,5);
  227.     deleteln();
  228.     mvaddstr(12,6,"insch():");
  229.     insch('X');
  230.     mvaddstr(20,5,"clrtobot():");
  231.     clrtobot();
  232.     refresh();
  233.     getch();
  234.  
  235.     mvaddstr(14,5,"insertln():");
  236.     insertln();
  237.     refresh();
  238.     getch();
  239.  
  240.     attrset(A_NORMAL);
  241.     clear();
  242.     scrollok(stdscr, TRUE);
  243.     for (i = 0; i < LINES; i++) {
  244.         move(i,0);
  245.         printw("The quick brown fox jumps over the lazy dog %d times", i);
  246.     }
  247.     refresh();
  248.     getch();
  249.     scroll(stdscr);
  250.     refresh();
  251.     getch();
  252.     scroll(stdscr);
  253.     refresh();
  254.     getch();
  255.  
  256.     endwin();
  257. #ifndef __AUX__
  258.     if (!isendwin())
  259.     ABORT("isendwin() returned false, should be true!\n");
  260. #endif
  261.  
  262.     exit(0);
  263. }
  264.  
  265.